var Bac = require("Bacteria");
var CCE = require("CameraController");
var GameOption = require("GameOption");

cc.Class({
    extends: cc.Component,

    properties: {
        TouchPont:cc.v2(0,0),
        Bacteria:{
            default:null,
            type:Bac
        },
        MainCamera:{
            default:null,
            type:CCE
        },
        Option:{
            default: null,
            type: GameOption
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // // onLoad () {},

    // start () {
    //     this.setInput();
    // },

    // update (dt) {},

    // setInput () {
    //     var self = this;
    //     self.node.on(cc.Node.EventType.TOUCH_START,function(event){self.TouchStart(event,self)},self);
    //     self.node.on(cc.Node.EventType.TOUCH_MOVE,function(event){self.Touching(event,self)},self);
    //     self.node.on(cc.Node.EventType.TOUCH_END,function(event){self.TouchEnd(event,self)},self);
    // },

    // TouchStart (event,self) {
    //     //console.log(self.MainCamera.NOtouching);
    //     self.MainCamera.NOtouching = false;
    //     //console.log(self.MainCamera.NOtouching);
    //     //console.log( cc.v2(self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).x - 540, self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).y - 960) );
    //     self.Bacteria.Arrow.active = true;
    // },

    // Touching (event,self) {
    //     var turn;
    //     if((self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).x - 540 - self.Bacteria.node.x) > 0){
    //         turn = Math.PI - Math.atan2((self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).y - 960 - self.Bacteria.node.y), (self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).x - 540 - self.Bacteria.node.x));
    //     } 
    //     else if((self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).x - 540 - self.Bacteria.node.x) < 0){
    //         turn = 2 * Math.PI + Math.atan2((self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).y - 960 - self.Bacteria.node.y), -(self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).x - 540 - self.Bacteria.node.x));
    //     }
    //     else{
    //         if((self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).y - 960 - self.Bacteria.node.y) > 0){
    //             turn = 0.5 * Math.PI;
    //         }
    //         else{
    //             turn  = -0.5 * Math.PI;
    //         }
    //     }
    //     self.Bacteria.Arrow.rotation = turn / Math.PI * 180 - 90;
    // },

    // TouchEnd (event,self) {
    //     this.MainCamera.NOtouching = true;
    //     var TouchALong = Math.sqrt((self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).x - 540 - self.Bacteria.node.x) * 
    //         (self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).x - 540 - self.Bacteria.node.x) +
    //         (self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).y - 960 - self.Bacteria.node.y) * 
    //         (self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).y - 960 - self.Bacteria.node.y)
    //     )
    //     var Speed = cc.v2((self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).x - 540 - self.Bacteria.node.x) * self.Option.ShootSpeed / TouchALong, 
    //         (self.MainCamera.Cameraa.getCameraToWorldPoint(event.getLocation()).y - 960 - self.Bacteria.node.y) * self.Option.ShootSpeed / TouchALong);
    //     self.Bacteria.ShootSpeed = Speed;
    //     self.Bacteria.Arrow.active = false;
    // }
});
